package com.ssy.lingxi.report.dao.pay;

import com.ssy.lingxi.report.model.bo.StatisticsCountBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 资金账户DAO
 * @author 伍将
 * @date 2020/11/14
 * @version 2.0.0
 */
@Service
public class AssetAccountDAO implements Serializable {
    private static final long serialVersionUID = -2296777955627292281L;


    @Autowired
    @Qualifier("payJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    /**
     * 获取资金账户统计数量
     * @return
     */
    public List<StatisticsCountBO> getAssetAccountStatisticsCount() {
        StringBuilder sql = new StringBuilder();
        sql.append(" select ")
                .append(" account.parent_member_id member_id,account.parent_member_role_id role_id,record.status status_type,count(*)")
                .append(" FROM ")
                .append(" pay_member_asset_account account")
                .append(" inner join pay_account_trade_record record")
                .append(" on account.id=record.member_asset_account_id")
                .append(" where record.operation=2")  //账户提现
                .append(" and record.status in (1,2)")     // 1-申请提现, 2-审核通过
                .append(" group by account.parent_member_id,account.parent_member_role_id,record.status");

        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(StatisticsCountBO.class));
    }

}
